from django.db import models


class Course(models.Model):
    css_image = models.ImageField(upload_to='course/', max_length=200, verbose_name='课程封面')
    css_name = models.CharField(max_length=20, verbose_name='课程名称')
    css_start_time = models.DateTimeField(verbose_name='选课开始时间')
    css_end_time = models.DateTimeField(verbose_name='选课截止时间')
    css_num = models.IntegerField(default=0, verbose_name='已选人数')
    css_max_num = models.IntegerField(default=40, verbose_name='最大学习人数')
    css_desc = models.CharField(max_length=200, verbose_name='课程简介')
    css_detail = models.TextField(verbose_name='课程详情')
    css_course_need = models.CharField(max_length=100, verbose_name='课程须知')
    css_school = models.ForeignKey('schools.School', on_delete=models.CASCADE, related_name='course_school',
                                   verbose_name='所属学校')
    css_teacher = models.ForeignKey('users.User', on_delete=models.CASCADE, related_name='course_teacher',
                                    verbose_name='授课教师')
    css_time = models.DateTimeField(auto_now_add=True, verbose_name='添加时间')

    def __str__(self):
        return self.css_name

    class Meta:
        verbose_name = '课程信息'
        verbose_name_plural = verbose_name
        db_table = 'course'
        ordering = ['css_num', '-css_end_time']
